package local

import (
	"fmt"
	"github.com/wailsapp/wails/v2/pkg/runtime"
	"xiuxian_help_tool/backend/app"
)

var FileServiceApp = new(FileService)

type FileService struct{}

// SelectFile 选择需要处理的文件
func (a *FileService) SelectFile(filetype string) string {
	if filetype == "" {
		filetype = "*.xlsx;"
	}
	selection, err := runtime.OpenFileDialog(app.App().Ctx(), runtime.OpenDialogOptions{
		Title: "选择文件",
		Filters: []runtime.FileFilter{
			{
				DisplayName: "文本数据",
				Pattern:     filetype,
			},
		},
	})
	if err != nil {
		return fmt.Sprintf("err %s!", err)
	}
	return selection
}
